extends Spatial


# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var x_sensitivity = 0
var y_sensitivity = 0
var is_drag = false
var planet
var helper
var camera
var view

func _input(event):
	if event is InputEventMouseButton:
		if event.button_index == BUTTON_RIGHT:
			is_drag = event.pressed
		if event.button_index == BUTTON_WHEEL_UP and Global.zoom > 0.1:
			Global.zoom -= .1
			camera.translation = Vector3(0,0,pow(Global.zoom,4)+1.1)
		if event.button_index == BUTTON_WHEEL_DOWN:
			Global.zoom += .1
			#print(zoom)
			camera.translation = Vector3(0,0,pow(Global.zoom,4)+1.1)

	if event is InputEventMouseMotion and is_drag:
		self.rotate_y(event.relative.x/x_sensitivity)
		helper.rotate_x(event.relative.y/y_sensitivity)

# Called when the node enters the scene tree for the first time.
func _ready():
	x_sensitivity = -200
	y_sensitivity = -200
	helper = get_node("helper")
	camera = get_node("helper/target")
	view = get_node("helper/real_camera")
	camera.translation = Vector3(0,0,pow(Global.zoom,4)+1.1)
	pass # Replace with function body.


func _on_Control_camera_change(text):
	for node in Global.objects:
		if node.name == text:
			var tmp_pos = view.get_global_transform()
			self.get_parent().remove_child(self)
			node.add_child(self)
			view.global_transform = tmp_pos
			
	pass # Replace with function body.
